#include "base.h"

namespace OPT
{
	extern int k_cover;
	extern int n_OMST;
	extern int min_P3P_matches;
	extern int min_P3P_inliers;
	extern int min_vis_views;
	extern int ra_conf;
	extern float min_tri_angle;
	extern float rigister_ratio;
	extern float points_level; // 0:all tracks, n:select n tracks
	extern string sGCPFile;
	extern string sBundlerFile;
	extern string sCameraFile;
	extern float fGPSErr;
	extern bool bSfMReport;
}

bool SfM(REC3D::ImageInfos& imageInfos, REC3D::ImagePairMatches& imagePairMatches, REC3D::SparsePoints& sparsePoints, string SfMDir)
{
	REC3D::SfMParams sfmParams;
	sfmParams.k_cover = OPT::k_cover;
	sfmParams.rigister_ratio = OPT::rigister_ratio;
	sfmParams.ra_conf = sfmParams.ra_conf;
	sfmParams.min_P3P_matches = OPT::min_P3P_matches;
	sfmParams.min_P3P_inliers = OPT::min_P3P_inliers;
	sfmParams.min_tri_angle = OPT::min_tri_angle;
	sfmParams.min_vis_views = OPT::min_vis_views;
	sfmParams.n_OMST = OPT::n_OMST;
	sfmParams.GCPFile = OPT::sGCPFile;
	sfmParams.bundlerFile = OPT::sBundlerFile;
	sfmParams.cameraFile = OPT::sCameraFile;
	sfmParams.points_level = OPT::points_level;
	sfmParams.gps_err = OPT::fGPSErr;
	sfmParams.sfm_report = OPT::bSfMReport;

	// group check
	#pragma omp parallel for schedule(dynamic)
	for (int i = 0; i < imageInfos.size(); i++)
	{
		REC3D::ImageInfo &imageInfo = imageInfos[i];
		imageInfo.fx += 0.1 * imageInfo.group_id;
		imageInfo.fy += 0.1 * imageInfo.group_id;
	}
	
	if (SfMSolver(imageInfos, imagePairMatches, sparsePoints, SfMDir, sfmParams))
		return 1;
	else
		return 0;
}